package com.usian.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.usian.model.common.dtos.PageResponseResult;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;
import com.usian.model.user.dtos.AuthDto;
import com.usian.model.user.pojos.ApUserRealname;
import com.usian.user.mapper.ApUserRealnameMapper;
import com.usian.user.service.ApUserRealnameService;
import org.springframework.stereotype.Service;

@Service
public class ApUserRealnameServiceImpl extends ServiceImpl<ApUserRealnameMapper, ApUserRealname> implements ApUserRealnameService {

    @Override
    public PageResponseResult loadApUserRealnameList(AuthDto dto) {
        //1：校验参数
        if(dto==null){
            return (PageResponseResult)ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        dto.checkParam();
        //2:构建条件查询
        LambdaQueryWrapper<ApUserRealname> lambdaQueryWrapper =new LambdaQueryWrapper<ApUserRealname>();
        if(dto.getStatus()!=null){
            lambdaQueryWrapper.eq(ApUserRealname::getStatus,dto.getStatus());
        }

        //QueryWrapper<ApUserRealname> queryWrapper =new QueryWrapper<>();
        //queryWrapper.lambda().eq(ApUserRealname::getStatus,dto.getStatus());

        Page page =new Page(dto.getPage(),dto.getSize());
        IPage result = page(page,lambdaQueryWrapper);
        PageResponseResult responseResult =new PageResponseResult(dto.getPage(),dto.getSize(),(int)result.getRecords().size());
        responseResult.setData(result.getRecords());
        return responseResult;
    }
}
